package com.woniuxy.microstockserver.mapper;

import com.woniuxy.microstockserver.bean.AllocationBean;
import com.woniuxy.microstockserver.bean.AllocationGoodsDetailsBean;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 赵雄伟
 * 调拨商品详情
 */
@Mapper
public interface AllocationGoodsDetailsMapper {
    /**
     * 新增入库单的新增入库商品
     * @param alloId
     * @param allocationBeans
     */
    @Insert("<script>" +
            "insert into t_allocation_goodsdetails_info (fk_goods_id,es_goods_remarks,fk_allo_id,delete_status,allo_goods_amount) values "+
            "<foreach collection='list' item='goods'  separator=','>"+
            "(#{goods.goodsId},#{goods.esGoodsRemarks},#{alloId},#{goods.deleteStatus},#{goods.alloGoodsAmount})"+
            "</foreach>"+
            "</script>")
    void saveAllocationGoodsDetailsBean(@Param("alloId") Long alloId, @Param("list") List<AllocationGoodsDetailsBean> allocationGoodsDetailsBeans);

    /**
     * 根据调拨单外键id查询调拨单商品详情
     */
    @Results({
            @Result(id = true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "goodsId",column = "fk_goods_id",javaType = Long.class),
            @Result(property = "esGoodsRemarks",column = "es_goods_remarks",javaType = String.class),
            @Result(property = "alloId",column = "fk_allo_id",javaType = Long.class),
            @Result(property = "deleteStatus",column = "delete_status",javaType = Byte.class),
            @Result(property = "alloGoodsAmount",column = "allo_goods_amount",javaType = Integer.class)
    })
    @Select("select * from t_allocation_goodsdetails_info where fk_allo_id = #{alloId}")
    List<AllocationGoodsDetailsBean> findAllocationAndGoodsDetail(@Param("alloId") Long id);

    /**
     * 根据调拨单外键id，删除调拨单商品信息，主要用于修改调拨单
     * @param id
     */
    @Delete("delete from t_allocation_goodsdetails_info where fk_allo_id = #{alloId}")
    void deleteByAlloId(@Param("alloId") Long id);
}
